package com.moonshineproject.plugin.filesearch
{
	import com.moonshineproject.plugin.PluginBase;
	import com.moonshineproject.plugin.filesearch.command.FileSearchBase;
	import com.moonshineproject.plugin.filesearch.command.FileSearch;
	import com.moonshineproject.text.TextLineModel;
	import com.moonshineproject.vo.Settings;
	
	import flash.events.Event;
	import flash.filesystem.File;
	
	public class FileSearchPlugin extends PluginBase
	{
		override public function get name():String { return "File search"; }
		override public function get author():String { return "Moonshine Project Team"; }
		override public function get description():String { return "Search for strings in files."; }

		override public function activate():void
		{
			super.activate();
			
			registerCommand("find", find);
		}

		override public function deactivate():void
		{
			super.deactivate();

			unregisterCommand("find");
		}
		
		private function find(args:Array):void
		{
			if (!model.activeProject)
			{
				error("No project open.");
				return;
			}
			else if (args[0] == null)
			{
				error("No search string.");
				return;
			}
			
			print("%s", args[0]);
			
			var search:FileSearchBase = getSearchCommand();
			
			if (search)
				search.search(args[0], model.activeProject.folder);
		}
		
		private function getSearchCommand():FileSearchBase
		{
			return new FileSearch();

			//if (Settings.os == "win")
			//{
				////error("Not implemented for windows.");
				////return null;	

				//return new WinFileSearch();
			//}
			//else
				//return new UnixFileSearch();
		}
	}

}
